//
//  WBAccount.swift
//  SinaWeibo
//
//  Created by 风不会停息 on 2016/11/15.
//  Copyright © 2016年 风不会停息. All rights reserved.
//

import UIKit

class WBAccount: NSObject,NSCoding {

    var access_token:String?
    
    var expires_in: Double = 0 {
        didSet {
            //一旦设置过期时间 就开始计算过期日期
            expires_date = Date(timeIntervalSinceNow: expires_in)
        }
    }
    var expires_date: Date?
    ///授权用户的UID，本字段只是为了方便开发者，减少一次user/show接口调用而返回的，第三方应用不能用此字段作为用户登录状态的识别，只有access_token才是用户授权的唯一票据。
    var uid: String?
    ///	友好显示名称
    var name: String?
    ///用户头像地址 180 * 180
    var avatar_large: String?
    
    //自定义构造函数
    init(dict: [String : Any]) {
        super.init()
        setValuesForKeys(dict)
    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
    }
    
    required init?(coder aDecoder: NSCoder) {

        access_token = aDecoder.decodeObject(forKey: "access_token") as?String
        expires_date = aDecoder.decodeObject(forKey: "expires_date")as? Date
         uid = aDecoder.decodeObject(forKey: "uid")as? String
         name = aDecoder.decodeObject(forKey: "name")as? String
         avatar_large = aDecoder.decodeObject(forKey: "avatar_large")as? String
        
        
    }
    
    func encode(with aCoder: NSCoder) {
        aCoder.encode(access_token, forKey: "access_token")
        aCoder.encode(expires_in, forKey: "expires_in")
        aCoder.encode(uid, forKey: "uid")
        aCoder.encode(name, forKey: "name")
        aCoder.encode(avatar_large, forKey: "avatar_large")
    }
    

}
